package com.example.springbootblog.common.pojo.result;

import com.example.springbootblog.common.enums.ResultStatusEnums;
import lombok.Data;

/**
 * 定义结果类型
 *
 * @param <T>
 */

@Data
public class Result<T> {
    //    状态码
    private Integer code;
    //    错误信息
    private String msg;
    //    数据信息
    private T data;

    // 成功情况
    public static <T> Result ok(T data) {
        Result result = new Result<>();
        result.setCode(ResultStatusEnums.SUCCESS.getCode());
        result.setMsg("返回成功");
        result.setData(data);
        return result;
    }

    // 失败情况
    public static <T> Result fail(String msg) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatusEnums.FAIL.getCode());
        result.setMsg(msg);
        return result;
    }

    public static <T> Result fail(String msg, Integer code) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMsg(msg);
        return result;
    }

}
